function useFullScreen() {
  const [isFullScreen, setIsFullscreen] = useState(false);

  useEffect(() => {
    // 阻止F11键默认事件，用全屏API代替
    window.addEventListener("keydown", handleKeyDown);
    document.addEventListener("fullscreenchange", handleFullscreenChange);
    return () => {
      window.removeEventListener("keydown", handleKeyDown);
      document.removeEventListener("fullscreenchange", handleFullscreenChange);
    };
  }, []);

  const handleKeyDown = (e) => {
    if (e.key === "F11" && !isFullScreen) {
      // 全屏模式下，按下 f11 和 esc 不会被响应
      e.preventDefault();
      toggleFullScreen();
    }
  };

  const toggleFullScreen = () => {
    if (!document.fullscreenElement) {
      // 进入全屏
      document.documentElement.requestFullscreen();
      setIsFullscreen(true);
    } else if (document.exitFullscreen) {
      // 退出全屏
      document.exitFullscreen();
      setIsFullscreen(false);
    }
  };

  const handleFullscreenChange = () => {
    if (!document.fullscreenElement) {
      // 按下 f11 和 esc 退出全屏后执行
      setIsFullscreen(false);
    }
  };

  return [isFullScreen, toggleFullScreen];
}
